package cn.fatgod.learn.mybatis.utils;

import cn.hutool.core.io.resource.ResourceUtil;
import lombok.Getter;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SqlSessionGenerator {
    @Getter
    private final static SqlSessionFactory FACTORY;

    static {
        FACTORY = new SqlSessionFactoryBuilder()
                .build(ResourceUtil.getStream("mybatis-config.xml"));
    }

    public static SqlSession generate(boolean autoCommit) {
        return FACTORY.openSession(autoCommit);
    }

    public static SqlSession generate() {
        return generate(false);
    }
}
